package com.sz.ruichar.controller.beans;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sz.ruichar.entity.beans.TUserInfo;
import com.sz.ruichar.entity.beans.TUserScore;
import com.sz.ruichar.interfs.beans.ITUserInfoService;
import com.sz.ruichar.interfs.beans.ITUserScoreService;
import com.sz.ruichar.interfs.beans.IWeixinUserService;
import com.sz.ruichar.service.entity.model.result.ResultData;

@RestController
@RequestMapping("/userInfo")
public class UserInfoController 
{
    private static Logger log = LoggerFactory.getLogger(UserInfoController.class);
    @Autowired
    private ITUserInfoService userInfoService;
    @Autowired
    private IWeixinUserService weixinUserService;
    
    
    @GetMapping(value="getUserInfo")
    public ResultData getUserInfo(String openid)
    {
    	if(openid == null && openid.isEmpty()){
    		return ResultData.error("error param");
    	}
    	TUserInfo info = userInfoService.getUserInfo(openid);
    	return ResultData.success(info);
    }
    
    @PostMapping(value="saveUserInfo")
    public ResultData saveUserInfo(@RequestBody TUserInfo userInfo){
    	if(userInfo == null){
    		return ResultData.error("error param");
    	}
    	userInfoService.saveUserInfo(userInfo);
    	return ResultData.success();
    }
    
    @GetMapping(value="getWeixinUserInfo")
    public ResultData getWeixinUserInfo(String openid)
    {
    	if(openid == null && openid.isEmpty()){
    		return ResultData.error("error param");
    	}
    	Map<String,Object> result = new HashMap<>();
    	result = weixinUserService.getWeixinUserInfo(openid);
    	return ResultData.success(result);
    }
    
    
    
}
